package com.example.arithmeticleetcode.leetcode;

/**
 * @program: arithmetic-leetcode
 * @description: 1395. 统计作战单位数
 * @author: FangZhen
 * @create: 2020-04-17 09:24
 **/
public class Demo03 {

    public static void main(String[] args) {
        int[] rating = {2, 5, 3, 4, 1};
        int[] rating1 = {2, 1, 3};
        int[] rating2 = {1, 2, 3, 4};
        System.out.println(numTeams(rating2));
    }

    public static int numTeams(int[] rating) {
        int count = 0;
        for (int i = 0, len = rating.length; i < len - 2; i++) {
            int first = rating[i];
            for (int j = i + 1; j < len - 1; j++) {
                int second = rating[j];
                for (int k = j + 1; k < len; k++) {
                    //升序
                    if (first < second && second < rating[k]) {
                        count++;
                    }
                    //降序
                    if (first > second && second > rating[k]) {
                        count++;
                    }
                }
            }
        }
        return count;
    }

}
